package com.jader.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jader.util.JaderApplication;
import com.zlp.jader.R;

public class SettingActivity extends Activity implements OnClickListener {
	LinearLayout layout_address;
	ImageView img_setting_back;
	TextView tv_setting_titile, tv_setting_about, tv_setting_help;
	CheckBox check_receiver, check_nosound;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		initView();
		viewListener();
	}

	private void viewListener() {
		check_receiver
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						if (check_receiver.isChecked()) {
							check_nosound.setClickable(true);
							check_nosound.setChecked(true);
							check_nosound.setTextColor(getResources().getColor(
									R.color.tv_Black));
						} else {
							check_nosound.setChecked(false);
							check_nosound.setClickable(false);
							check_nosound.setTextColor(getResources().getColor(
									R.color.tv_70Black));
						}
					}
				});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.layout_addressmanager:
			if (JaderApplication.user == null) {
				JaderApplication.login(this);
			} else {
				Intent address = new Intent(this, AddressManagerActivity.class);
				startActivity(address);
			}
			break;
		case R.id.top_actionbar_back:
			finish();
			break;
		case R.id.tv_setting_about:
			startActivity(new Intent(this, AboutActivity.class));
			break;
		case R.id.tv_setting_help:
			startActivity(new Intent(this, HelpActivity.class));
			break;
		default:
			break;
		}

	}

	private void initView() {
		tv_setting_titile = (TextView) findViewById(R.id.top_actiobar_text);
		tv_setting_titile.setText("个人设置");
		tv_setting_about = (TextView) findViewById(R.id.tv_setting_about);
		tv_setting_help = (TextView) findViewById(R.id.tv_setting_help);
		img_setting_back = (ImageView) findViewById(R.id.top_actionbar_back);
		layout_address = (LinearLayout) findViewById(R.id.layout_addressmanager);
		check_nosound = (CheckBox) findViewById(R.id.check_setting_nosound);
		check_receiver = (CheckBox) findViewById(R.id.check_setting_receive);
		layout_address.setOnClickListener(this);
		img_setting_back.setOnClickListener(this);
		tv_setting_about.setOnClickListener(this);
		tv_setting_help.setOnClickListener(this);
	}
}
